<?php
	
//if($_SERVER['REQUEST_METHOD'] == 'POST'){
	require_once('config.php');
	require_once('include/ClaimsAPIService.php');
	require_once('include/EligibilityAPIServicePort.php');
	require_once('include/functions.php');
	
	$claimsAPIServiceClient = new ClaimsAPIService($claimsAPIServiceWSDL,array());
	
	/* request a ticket */
	/* build request ticket info */
	$requestTicketInfo = new RequestTicket();
	$requestTicketInfo->username = $username;
	$requestTicketInfo->password = $password;
	$requestTicketResponse = $claimsAPIServiceClient->RequestTicket($requestTicketInfo);
	$authTicket = $requestTicketResponse->RequestTicketResult;
	$error = new ErrorMessage();
	/* check for error */
	if(strlen($authTicket) == 1){
		switch($authTicket){
			/*
			 *  "G” – User account could not be found
			 *	“H” – User account is not activ
			 *	“I” – User account has expired
			 *	“B” – User account is locked out
			 *	“E” – User account attempted login with the wrong password
			 */
			case 'G':
				$error->Code = 'G';
				$error->Text = 'User account could not be found.';
				break;
			case 'H':
				$error->Code = 'H';
				$error->Text = 'User account is not active.';
				break;
			case 'I':
				$error->Code = 'I';
				$error->Text = 'User account has expired.';
				break;
			case 'B':
				$error->Code = 'B';
				$error->Text = 'User account is locked out.';
				break;
			case 'E':
				$error->Code = 'E';
				$error->Text = 'User account attempted login with the wrong password';
				break;
			default:
				$error->Code = 'U';
				$error->Text = 'Unknown error occurred.';
		}
		echo "Can not get the authentication ticket. We are facing an error: <br />";
		echo $error->Text;
		exit;	
	}
	/* request uuid */
	$rqstRefGUID  = uuid("");
	/* DtType */	
	$arr_DtType = array('ServiceDate', 'ProcessDate', 'PayDate');	
	$dtType = $arr_DtType[rand(0,2)];
	$inclPaid = rand(0,1);
	$inclUnpaid = rand(0,1);		
	$inclWI = rand(0,1);
    $inclAddr = rand(0,1);
    $autobenPolicyNum = '992059105';
    $tpPolicyNum = '44001';
    $frmDt = '2008-01-01';
    $toDt = '2010-01-01';    
	
	/* echo sample input */
	echo "Make a call with: <br />";
	echo "<ul>";
	echo "<li> AutobenPolicyNum: " . $autobenPolicyNum . "</li>";
	echo "<li> TPPolicyNum: " . $tpPolicyNum . "</li>";
	echo "<li> FrmDt: " . $frmDt . "</li>";
	echo "<li> ToDt: " . $toDt . "</li>";
	echo "<li> RqstRefGUID: " . $rqstRefGUID . "</li>";
	echo "<li> AuthTicket: " . $authTicket . "</li>";
	echo "<li> AuthTicket: " . $authTicket . "</li>";
	echo "<li> DtType: " . $dtType . "</li>";
	echo "<li> InclPaid: " . (($inclPaid)?"True":"False") . "</li>";
	echo "<li> InclUnpaid: " . (($inclPaid)?"True":"False") . "</li>";
	echo "<li> InclUnpaid: " . (($inclUnpaid)?"True":"False") . "</li>";
	echo "<li> InclWI: " . (($inclWI)?"True":"False") . "</li>";
	echo "<li> InclAddr: " . (($inclAddr)?"True":"False") . "</li>";
	echo "</ul>";
	
	/* Make the GetBatchClaims call */
	$getBatchClaimsRequest = new GetBatchClaims();
	$getBatchClaimsRequestDto = new GetBatchClaimsRequestDto();
	$getBatchClaimsRequestDto->ExpAll = true;	
	$getBatchClaimsRequestDto->FrmDt = $frmDt;
	$getBatchClaimsRequestDto->ToDt = $toDt;
	$getBatchClaimsRequestDto->Groups = array();
	$getBatchClaimsRequestDto->Groups[0] = new EmployerCredentialDto();
	$getBatchClaimsRequestDto->Groups[0]->Divs->nil = true;
	$getBatchClaimsRequestDto->Groups[0]->AutobenPolicyNum = $autobenPolicyNum;
	$getBatchClaimsRequestDto->Groups[0]->TPPolicyNum = $tpPolicyNum;
	$getBatchClaimsRequestDto->InclAddr = $inclAddr;
	$getBatchClaimsRequestDto->InclPaid = $inclPaid;
	$getBatchClaimsRequestDto->InclUnpaid = $inclUnpaid;
	$getBatchClaimsRequestDto->InclWI = $inclWI;
	$getBatchClaimsRequestDto->DtTyp = $dtType;
	$getBatchClaimsRequest->request = $getBatchClaimsRequestDto;
	$getBatchClaimsRequest->request->Ver = "1.0";
	$getBatchClaimsRequest->request->RqstRefGUID = $rqstRefGUID;
	$getBatchClaimsRequest->request->AuthTicket = $authTicket;
	$getBatchClaimsResponse = $claimsAPIServiceClient->GetBatchClaims($getBatchClaimsRequest);
	echo "<pre>";
	var_dump($getBatchClaimsResponse);
	echo "</pre>";
	
	
//}